package org.bluedream.core.module.sys.service.dict;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.commons.collections.map.HashedMap;
import org.bluedream.comm.utils.EmptyUtil;
import org.bluedream.core.module.base.OrgBaseServiceImpl;
import org.bluedream.core.module.sys.dao.dict.DictTypeDao;
import org.bluedream.core.module.sys.entity.dict.DictType;
import org.bluedream.core.utils.UserUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Map;

/**
 * @ClassName DictTypeService
 * @Description TODO
 * @Author foxsand
 * @Data 2021-09-09 16:52
 * @Version
 */
@Service
@DS("master")
@Transactional(
        readOnly = true
)
public class DictTypeService extends OrgBaseServiceImpl<DictTypeDao , DictType> implements IService<DictType> {
    private static final Logger logger = LoggerFactory.getLogger(DictTypeService.class);

    @Override
    public DictType getById(Serializable id) {
        if (EmptyUtil.isEmpty(id)){
            return new DictType();
        }
        return super.getById(id);
    }

    public IPage<DictType> findPage(DictType entity, String... args) {
        Map<String , Object> search = new HashedMap();
        if (EmptyUtil.isNoEmpty(entity.getDictName())
                || EmptyUtil.isNoEmpty(entity.getDictType())
                || EmptyUtil.isNoEmpty(entity.getOrgCode())
        ){
            if (EmptyUtil.isNoEmpty(entity.getDictName())){
                search.put("dict_name" , entity.getDictName());
            }
            if (EmptyUtil.isNoEmpty(entity.getDictType())){
                search.put("dict_type" , entity.getDictType());
            }
            if (EmptyUtil.isNoEmpty(entity.getOrgCode())){
                search.put("org_code" , entity.getOrgCode());
            }
        }
        return super.findPage(entity , search , args);
    }
}
